<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>父组件</h1>
        <zi-com :fdata="msg" :mycolor="'green'" :list="prolist" :myname="'铁锤妹妹'"></zi-com>
    </div>
    <!-- 子组件的模板 -->
    <template id="zi">
      <div>
          <h1>{{fdata}}</h1>
          <h1 :style="{color:mycolor}">{{myname}}</h1>
          <ul>
              <li v-for="(item,index) in list" :key="index">{{item}}</li>
          </ul> 
      </div>
    </template>
    <script src="./vue.js"></script>
    <script>
        // vue父组件向子组件传参
        // 1.子组件定义props 
        // 2.父组件通过v-bind:props 传送数据
        // 由于vue的props是单向数据流 在子组件中不能修改props的值
        // 容易发生错乱
        new Vue({
            el: "#app",
            data() {
                return {
                    msg: '哈哈哈',
                    prolist: ["杯子", "水壶", "养生壶"]
                }
            },
            props: [],
            components: {
                "ziCom": {
                    template: "#zi",
                    // props: ["fdata", "myname", "list", "mycolor"],
                    props: {
                        fdata: {
                            type: String,
                            required: true, //必传
                        },
                        myname: {
                            type: String,
                            required: true, //必传
                        },
                        list: {
                            type: Array
                        },
                        kk: [String, Number], //可以传送多个数据类型
                        mycolor: {
                            type: String,
                            default: 'red' //给props设置的默认数据
                        }
                    },
                    data() {
                        return {
                            zidata: "哈喽啊"
                        }
                    },
                    mounted() {
                        console.log(this.myname)
                            // this.myname = "121321"
                    },
                }
            }
        })
    </script>
</body>

</html>